/* eslint-disable no-debugger */
import axios from '@/http/request' // 导入http中创建的axios实例
import qs from 'qs' // 根据需求是否导入qs模块
import { baseUrl } from '@base' // 导入接口域名列表
import * as bUrl from '@/const/base.product.js'
const { baseUrl: productUrl } = bUrl
console.log(baseUrl)
console.log(productUrl)
const myFetch = (url, params, method = 'POST') => {
  if (method === 'POST') {
    return axios.post(`${baseUrl}/${url}`, qs.stringify(params))
  } else if (method === 'GET') {
    return axios.get(`${baseUrl}/${url}`, params)
  } else if (method === 'SPOST') {
    return axios.post(`${baseUrl}/${url}?${qs.stringify(params)}`, {})
  }
}

// 用来获取图片验证码的id
export const getCaptchaId = param => myFetch('ucenter/getCaptchaId.xhtml', param)
// 获取图片验证码url
export const getCaptchaIdUrl = captchaId => `${productUrl}/ucenter/captcha.xhtml?captchaId=${captchaId}&r=${Date.now()}`
// 获取手机号短信验证码
export const sendBindMsg = param => myFetch('ucenter/rest/sendBindMsg.xhtml', param)
// 注册第一步
export const createAndLoginWithBindMobile = param => myFetch('ucenter/rest/createAndLoginWithBindMobile.xhtml', param)
// 注册第二步
export const register = param => myFetch('vendor/member/register.xhtml', param)
// 正常登陆
export const postLoginNormal = (param) => myFetch('ucenter/rest/pcLoginByPass.xhtml', param, 'POST')
// 登录 "/rest/loginByPass.xhtml 多次密码有问题的
export const postLogin = (param) => myFetch('ucenter/rest/loginByPass.xhtml', param, 'POST')

// 获取票种
export const getDefaultSchedules = (param) => myFetch('vendor/program/getDefaultSchedules.xhtml', param, 'POST')
// 场馆id 查询可预约时期
export const getReservedateList = (scheduleId) => myFetch('vendor/reserve/getReservedateList.xhtml', { scheduleId }, 'POST')
// 预约时间段
export const getReservePeriodList = (param) => myFetch('vendor/reserve/getReservePeriodList.xhtml', param, 'POST')
// 获取参观人数据
export const getMemberTicketInfoList = (param) => myFetch('vendor/member/getMemberTicketInfoList.xhtml', param, 'POST')

// 新增修改参观人数据
export const saveMemberTicketInfo = (param) => myFetch('vendor/member/saveMemberTicketInfo.xhtml', param, 'POST')
// 获取支付方式 vendor/member/getPaymethods.xhtml
export const getPaymethods = (command) => myFetch('vendor/member/getPaymethods.xhtml', { command }, 'POST')
// 确认订单
export const payOrder = (command) => myFetch('vendor/member/order/payOrder.xhtml', { command }, 'POST')
// 获取订单列表
export const orderList = (param) => myFetch('vendor/member/order/orderList.xhtml', param, 'POST')
// 取消订单
export const cancelOrder = (tradeNo) => myFetch('vendor/member/order/cancelOrder.xhtml', { tradeNo }, 'POST')
// export const repeatedOrderRefund = (serialno) => myFetch('vendor/member/order/cancelOrder.xhtml', { serialno }, 'POST')
// 通过下单参数获取支付方式    String appId, String platform    vendor/member/getPaymethods.xhtml
export const getPaymethods1 = (param) => myFetch('vendor/member/getPaymentGatewayList.xhtml', param, 'SPOST')
// 退款退单
export const applyOrderRefund = (param) => myFetch('vendor/member/order/applyOrderRefund.xhtml', param, 'POST')
// 继续支付
export const repeatedPayOrder = (param) => myFetch('vendor/member/order/repeatedPayOrder.xhtml', param, 'POST')
// 获取详情
export const orderResult = (param) => myFetch('vendor/member/order/orderResult.xhtml', param, 'POST')
// 检测是否满足优惠条件
export const checkOrderVisitorInfos = (param) => myFetch('vendor/member/order/checkOrderVisitorInfos.xhtml', param, 'POST')
// 绑定关联成人
export const bindCertificate = (param) => myFetch('vendor/member/reserve/bindCertificate.xhtml', param, 'POST')
// check 检查能不能被关联 vendor/member/order/checkOrderVisitorInfo.xhtml
export const checkOrderVisitorInfo = (param) => myFetch('vendor/member/order/checkOrderVisitorInfo.xhtml', param, 'POST')
// 退出登录  /ucenter/rest/logout.xhtml
export const logout1 = param => myFetch('ucenter/rest/logout.xhtml', param, 'GET')
// 获取用户信息
export const getLogonInfo = param => myFetch('ucenter/rest/getLogonInfo.xhtml', param)

// // 忘记密码 重置密码 验证码
// sign, captcha, captchaId, email
// export const postForgetCode = (param) => myFetch('/ucenter/rest/sendEmailResetPasswordMsg.xhtml',param,'POST');

// // 重置密码
// let params = {checkpass:code,email,newUserpass:pwd};
// export const postRestPwd= (param) => myFetch('/ucenter/rest/resetPassword.xhtml',param,'POST');

// ali支付
export const payAli = (param) => {
  const { submitParams, httpMethod, payurl } = param

  // const submitParams = {
  //   alipay_sdk: 'alipay-sdk-java-dynamicVersionNo',
  //   charset: 'UTF-8',
  //   biz_content: '{"body":"请在2021-04-11 12:05:56前付款","out_trade_no":"2421041111501486","product_code":"QUICK_WAP_PAY","subject":"请在2021-04-11 12:05:56前付款","timeout_express":"15m","total_amount":"0.01"}',
  //   amount: 0.01,
  //   method: 'alipay.trade.wap.pay',
  //   tradeNo: '2421041111501486',
  //   format: 'json',
  //   sign: 'gM96DQc3hYfhvOzG/3aEms6ho1tvgrIPbLF7dOSaV5Axp1Eaa/rdrIW6Ourtz7fe0/aNuaYrmrtwOXiq0jKD5dlKfCWr2AZiE/JSGgs+/XHDd2aMYX0naA0guiegMiuO8dJJuVRPjE79J1pYuFE6Xsyc4RuG5iPz70KbyEy+paDr10YohNaaBtLMX4029aN4ssnBcbua6xHtPVwDV6UPEd90bDwSX4FHigoUyOz0g2S+8rs2+0oUhrx5No7sYHOjlXEKKlC+cSTREYAbeml25Q0Q3FElIsu6NXHah/EWVy6id5d9YHbxs4UBzXQU8e4l31ShrG2Uj6TnkVJ/idMw2w==',
  //   notify_url: 'http://www.cfexpo2021.com/pay//alipayWapNotify.xhtml',
  //   version: '1.0',
  //   __tradeNo: '2421041111501486',
  //   return_url: 'http://www.cfexpo2021.com/pay//alipayWapReturn.xhtml',
  //   app_id: '2021002131604645',
  //   sign_type: 'RSA2',
  //   timestamp: '2021-04-11 11:50:56'
  // }
  // 如文件、字节流，剔除sign字段。
  //   REQUEST URL: https://openapi.alipay.com/gateway.do
  // REQUEST METHOD: POST
  // CONTENT:
  //  app_id=2014072300007148
  //  method=alipay.mobile.public.menu.add
  //  charset=GBK
  //  sign_type=RSA2
  //  timestamp=2014-07-24 03:07:50
  //  biz_content={"button":[{"actionParam":"ZFB_HFCZ","actionType":"out","name":"话费充值"},{"name":"查询","subButton":[{"actionParam":"ZFB_YECX","actionType":"out","name":"余额查询"},{"actionParam":"ZFB_LLCX","actionType":"out","name":"流量查询"},{"actionParam":"ZFB_HFCX","actionType":"out","name":"话费查询"}]},{"actionParam":"http://m.alipay.com","actionType":"link","name":"最新优惠"}]}
  //  sign=e9zEAe4TTQ4LPLQvETPoLGXTiURcxiAKfMVQ6Hrrsx2hmyIEGvSfAQzbLxHrhyZ48wOJXTsD4FPnt+YGdK57+fP1BCbf9rIVycfjhYCqlFhbTu9pFnZgT55W+xbAFb9y7vL0MyAxwXUXvZtQVqEwW7pURtKilbcBTEW7TAxzgro=
  //  version=1.0
  const temp = document.createElement('form')
  temp.action = `${payurl}`
  temp.method = `${httpMethod}`
  temp.style.display = 'none'
  for (const x in submitParams) {
    const opt = document.createElement('textarea')
    opt.name = x
    opt.value = submitParams[x]
    temp.appendChild(opt)
  }

  document.body.appendChild(temp)
  temp.submit()
  document.body.removeChild(temp)
}
